<!--会员中心 》发布招工信息-->
<template>
  <div style="width: 100%;height: 600px;margin-left: 60px;;
        padding: 20px 20px;box-sizing: border-box;font-size: 17px;text-align: left">

  </div>
</template>

<script>
export default {
  name: "MemberReleaseRecuitInfoView",
  data() {
    return {
      dialogVisible: false,
      dialogVisible1: false,
      IndustryList: [{id: '', detailName: '', peId: ''}],
      WorkList: [],
      workInfo: [],
      selectedwork: [],
      selectedworkObject: [],
      tempSelectWork: [],
      index: 0,

      DistrictList: [],
      district: '',
      props: {
        label: "district",
        value: "id",
        children: "list",
      },

      industryId: [],
      salary: '',
      releSalaryselected: {
        userId: '',
        selectedwork: [],
        district: '',
        industryId: [],
        phone: '',
        salary: '',
        settlement: '',
        content: '',
        number: "",
        term: "",
        imageUrl: [],
      },
      settlement: '',
      number: "",
      term: "",
      salarys: [
        {settlement: "元/天"},
        {settlement: "元/月"},
        {settlement: "元/米"},
        {settlement: "元/平"},
        {settlement: "元/方"},
        {settlement: "面议"},
      ],
      numberPeople: [
        {number: "1-2人"},
        {number: "3-5人"},
        {number: "6-10人"},
        {number: "11-20人"},
        {number: "20以上"},
      ],
      Duration: [
        {term: "1-4天"},
        {term: "5-14天"},
        {term: "15-30天"},
        {term: "1-2个月"},
        {term: "3-6个月"},
        {term: "长期"},
      ],
      phone: "",

      imageUrlTempNull: '',
      imageUrl1: '',
      imageUrl2: '',
      imageUrl3: '',


    };
  },
  methods: {
    inputInsert(item,ktem) {
      this.selectedworkObject.push(ktem);
      for (let i = 0; i < this.IndustryList.length; i++) {
        if (this.IndustryList[i].id == item.peId) {
          this.industryId.push(this.IndustryList[i].id);
          break;
        }
      }
    },
    showDialog() {
      this.dialogVisible = true;
    },
    closeSelect() {
      this.selectedwork = []
    },
    enterSelect() {
      this.dialogVisible = false;
      console.log(this.selectedwork)
    },
    //选择行业
    selectIndustry(item) {
      this.workInfo = item.list;
      this.WorkList = []
      this.index = 1;
    },
    //选择工种分类
    selectWork(item) {
      this.WorkList = item.list
      this.selectedwork.push(item);
    },
    handleClose(i) {
      this.selectedwork.splice(i, 1);
      this.industryId.splice(i,1);
      this.selectedworkObject.splice(i,1);
    },
    selectedAll() {
      this.workInfo = this.tempSelectWork;
    },

    handleRemove1(file, fileList) {//当点击删除图片时调用的方法
      this.imageUrl1 = this.imageUrlTempNull;//删除图片后让user的图片路径恢复之前的路径
      // 向服务器发请求删除服务器的图片 file.response=JsonResult
      // file.response.data 删除文件对应的图片路径
      this.axios.post( 'http://localhost:29000/v1/remove?url=' + file.response.data)
          .then((response) => {
            if (response.data.code == 1) {
              this.$message.success("删除完成！");
            }
          })
    },
    handleAvatarSuccess1(res, file) {
      this.imageUrl1 = res.data;
      console.log(this.imageUrl1);
    },
    beforeAvatarUpload1(file) {
      this.imageUrl1 = file.url;
      this.dialogVisible1 = true;
    },

    handleRemove2(file, fileList) {//当点击删除图片时调用的方法
      this.imageUrl2 = this.imageUrlTempNull;//删除图片后让user的图片路径恢复之前的路径
      // 向服务器发请求删除服务器的图片 file.response=JsonResult
      // file.response.data 删除文件对应的图片路径
      let jwt=JSON.parse(localStorage.getItem('user')).token;
      this.axios
          .create({
            'headers': {
              'Authorization': jwt
            }
          })
          .post( 'http://localhost:29000/v1/remove?url=' + file.response.data)
          .then((response) => {
            if (response.data.code == 1) {
              this.$message.success("删除完成！");
            }
          })
    },
    handleAvatarSuccess2(res, file) {
      this.imageUrl2 = res.data;
    },
    beforeAvatarUpload2(file) {
      this.imageUrl2 = file.url;
      this.dialogVisible1 = true;
    },

    handleRemove3(file, fileList) {//当点击删除图片时调用的方法
      this.imageUrl3 = this.imageUrlTempNull;//删除图片后让user的图片路径恢复之前的路径
      // 向服务器发请求删除服务器的图片 file.response=JsonResult
      // file.response.data 删除文件对应的图片路径
      let jwt=JSON.parse(localStorage.getItem('user')).token;
      this.axios
          .create({
            'headers': {
              'Authorization': jwt
            }
          })
          .post('http://localhost:29000/v1/remove?url=' + file.response.data)
          .then((response) => {
            if (response.data.code == 1) {
              this.$message.success("删除完成！");
            }
          })
    },
    handleAvatarSuccess3(res, file) {
      this.imageUrl3 = res.data;
    },
    beforeAvatarUpload3(file) {
      this.imageUrl3 = file.url;
      this.dialogVisible1 = true;
    },

    //发布
    release() {
      //releSalaryselected: {userId:'',selectedwork:[],district:'',phone:'',salary:'',settlement:'',content:'',number:"",term:"",imageUrl:[]},
      this.releSalaryselected.userId = 1;
      this.releSalaryselected.selectedwork = this.selectedworkObject;
      this.releSalaryselected.district = this.district;
      this.releSalaryselected.phone = this.phone;
      this.releSalaryselected.salary = this.salary;
      this.releSalaryselected.settlement = this.settlement;
      this.releSalaryselected.number = this.number;
      this.releSalaryselected.term = this.term;
      this.releSalaryselected.content = this.wangEditor.txt.html();
      this.releSalaryselected.industryId = this.industryId;
      this.releSalaryselected.imageUrl.push(this.imageUrl1);
      this.releSalaryselected.imageUrl.push(this.imageUrl2);
      this.releSalaryselected.imageUrl.push(this.imageUrl3);
      let jwt=JSON.parse(localStorage.getItem('user')).token;
      this.axios
          .create({
            'headers': {
              'Authorization': jwt
            }
          })
          .post("http://localhost:29000/v1/lookwork/addNew", this.releSalaryselected)
          .then((response) => {
            if (response.data.code == 20000) {
              this.$message.success("发布成功！");
              this.$router.push('/lookwork');
            } else {
              this.$message.error(response.data.message);
            }
          })
    }

  },
  mounted() {
    this.user=localStorage.getItem("user");
    if(this.user==null){
      this.$message.error("请登录后重试！")
      this.$router.push('/login')
    }

    this.axios.get('http://localhost:36000/v1/lookwork/industry')
        .then((response) => {
          if (response.data.code == 20000) {
            this.IndustryList = response.data.data;
            for (let i = 0; i < this.IndustryList.length; i++) {
              for (let j = 0; j < this.IndustryList[i].list.length; j++) {
                this.workInfo.push(this.IndustryList[i].list[j]);
              }
            }
            this.tempSelectWork = this.workInfo;
          }
        })

    this.axios.get('http://localhost:36000/v1/lookwork/districtAll')
        .then((response) => {
          if (response.data.code == 20000) {
            this.DistrictList = response.data.data;
          }
        })

    //通常在此处做一些初始化操作,比如富文本编辑器初始化, 或者发请求的代码
    //初始化富文本编辑器
    this.wangEditor = new this.wangEditor("#content_div");
    this.wangEditor.create();
  }
}
</script>

<style scoped>


</style>